package homework01;

import java.util.ArrayList;

import static sun.swing.MenuItemLayoutHelper.max;

/*
* 1. 在一个列表中存储以下元素：apple,grape,banana,pear； 
1)返回集合中的最大的和最小的元素 
2)将集合进行排序，并将排序后的结果打印在控制台上*/
public class ListAdd01 {
    public static void main(String[] args) {
        ArrayList<String> arrayList=new ArrayList<String>();
        arrayList.add("apple");
        arrayList.add("grape");
        arrayList.add("banana");
        arrayList.add("pear");
        System.out.println("最大值为："+max(arrayList));
        System.out.println("最小值为："+mix(arrayList));
        System.out.println("排序后："+score(arrayList));
    }

    private static ArrayList<String> score(ArrayList<String> arrayList) {
        ArrayList<String> temp=new ArrayList<String>(arrayList);
        ArrayList<String> list=new ArrayList<String>();
        for (int k=0;k<arrayList.size();k++){
            String max = max(temp);
            list.add(max);
            temp.remove(max);
        }
        return list;
    }
    private static String mix(ArrayList<String> arrayList) {
        int j=0;
        for (String str1:arrayList){
            for (String s2:arrayList){
                if (str1.compareTo(s2)<0){
                    j++;
                    return str1;
                }
            }
        }
        return null;
    }
    private static String max(ArrayList<String> arrayList) {
        int i=0;
        for (String str:arrayList){
            for (String s1:arrayList){
              if (str.compareTo(s1)>0) {
                  i++;
              }
            }
            if (i==arrayList.size()-1){
                return str;
            }
        }
        return  null;
    }

}
